﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
using PhotoList.Dal;
using QT.Basic;

namespace PhotoList.Web
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.tbUserID.Text.Trim()))
            {
                new Tools().Alert("请输入用户名！");
                return;
            }

            Regex rgx = new Regex(@"^[a-zA-Z][a-zA-Z0-9_.]{1,8}[a-zA-Z0-9]$");
            if (!rgx.IsMatch(this.tbUserID.Text))
            {
                new Tools().Alert("输入的用户名不合法！规则如下：\\n\\n只能包含字母、数字和下划线\\n必须以字母开始\\n长度为3至10个字符");
                return;
            }

            PhotoList.Dal.User uUser = new PhotoList.Dal.User();
            uUser.Uid = this.tbUserID.Text;
            uUser.Pass = new QT.Basic.Tools().MD5(this.tbPass.Text.Trim());

            if (uUser.Login())
            {
                this.Session["QT_UID"] = this.tbUserID.Text;
                this.Session["QT_PASS"] = new QT.Basic.Tools().MD5(this.tbPass.Text.Trim());
                this.Session.Timeout = 15;
                this.Response.Redirect("default.aspx");
            }
            else
            {
                new QT.Basic.Tools().Alert("用户名或密码错误");
            }
        }
    }
}